{template 'web/'.$cfg['floder'].'/base_menu'}
<div class="top_tab">
    <a href="{php echo $this->createWebUrl('settings')}" class="layui-btn {if $operation != 'display'}layui-btn-primary{/if}">系统参数1</a>
</div>
{if $operation == 'display'}
<style>
    ul.menu{ background:#FFF; border:1px solid #DDD;box-shadow: 0 0 2px #DDD; }
    ul.menu li .micon{display:inline-block; margin-right:10px; border-radius:100%; background:#19B394; width:20px; height:20px; line-height:20px; text-align:center}
    ul.menu li .micon i{color:#FFF;}
    ul.menu li a{ display:block;padding:15px 15px;}
    ul.menu li .pull-right{ display:none}
    ul.menu li.isselect,ul.menu li:hover{color:#FFF; background:#19B394;}
    ul.menu li.isselect .micon,ul.menu li:hover .micon{color:#FFF;background:rgba(255, 255, 255, 0.8)}
    ul.menu li.isselect .micon i,ul.menu li:hover .micon i{color:#19B394;}
    ul.menu li.isselect a,ul.menu li:hover a{color:#FFF;}
    ul.menu li.isselect .pull-right,ul.menu li:hover .pull-right{ display:block}
    .col-md-10 .panelbox{ display:none;}

    .col-md-10 .layui-form-label{width:140px}
    .col-md-10 .layui-input-block{margin-left:140px;}
    #tempmsg_payparama input{ display:inline-block}
    #tempmsg_payparama .layui-input { width:auto}
</style>
<form action="" method="post" class="layui-form" enctype="multipart/form-data">
    <div class="row">
        <div class="col-md-2">
            <ul class="menu">
                <li class="isselect" onclick="showTab(this)"><a href="javascript:"><span class="micon"><i class="fa fa-user"></i></span>系统参数<span class="pull-right"><i class="fa fa-menu-right"></i></span></a></li>
                <li onclick="showTab(this)"><a href="javascript:"><span class="micon"><i class="fa fa-user"></i></span>基本设置 <span class="pull-right"><i class="fa fa-menu-right"></i></span></a></li>
                <li onclick="showTab(this)"><a href="javascript:"><span class="micon"><i class="fa fa-user"></i></span>支付参数 <span class="pull-right"><i class="fa fa-menu-right"></i></span></a></li>
                <li onclick="showTab(this)"><a href="javascript:"><span class="micon"><i class="fa fa-user"></i></span>卡券/会员参数 <span class="pull-right"><i class="fa fa-menu-right"></i></span></a></li>
                <li onclick="showTab(this)"><a href="javascript:"><span class="micon"><i class="fa fa-user"></i></span>模板消息<span class="pull-right"><i class="fa fa-menu-right"></i></span></a></li>
            </ul>
        </div>
        <div class="col-md-10">
            <div class="panelbox" style="display:block">
                <div class="panelbox-head">系统参数</div>
                <div class="panelbox-body">
                    <div class="layui-form-item">
                        <label class="layui-form-label">调试开关</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="debug" lay-skin="switch" value="1" {if $cfg['debug']}checked{/if} lay-text="打开|关闭"/>
                            <div class="help-block">建议放公众号二维码</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">授权地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="siteroot" value="{$_W['siteroot']}" readonly autocomplete="off" class="layui-input"/>
                            <input type="hidden" name="softkey" value="{$cfg['softkey']}" />
                            <input type="hidden" name="floder" value="{$cfg['floder']}" />
                            <div class="help-block">授权地址,无需更改</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">服务器IP</label>
                        <div class="layui-input-block">
                            <input type="text" name="mch_create_ip" value="{$cfg['mch_create_ip']}" class="form-control"/>
                            <div class="help-block">所在服务器IP地址</div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="panelbox">
                <div class="panelbox-head">基本设置</div>
                <div class="panelbox-body">
                    <div class="layui-form-item">
                        <label class="layui-form-label">LOGO</label>
                        <div class="layui-input-block">
                            {php echo tpl_form_field_image('logo', $cfg['logo']);}
                            <div class="help-block"></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">公众号二维码</label>
                        <div class="layui-input-block">
                            {php echo tpl_form_field_image('qrcode', $cfg['qrcode']);}
                            <div class="help-block">出现在小票，部分页面中</div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">帮助中心连接</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" name="helplink" value="{$cfg['helplink']}"/>
                            <div class="help-block">前台帮助中心连接，不填写前台将不显示</div>
                        </div>
                    </div>


                </div>
            </div>
            <div class="panelbox">
                <div class="panelbox-head">支付参数</div>
                <div class="panelbox-body">
                    <blockquote class="layui-elem-quote layui-quote-nm">银行通道</blockquote>
                    <div class="layui-form-item">
                        <label class="layui-form-label">开启</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="isbank" lay-skin="switch" value="1" {if $cfg['isbank']}checked{/if} lay-text="开启|关闭"/>
                            <div class="help-block"></div>
                        </div>
                    </div>
                    <div class="layui-form-item" >
                        <label class="layui-form-label">银行商户号</label>
                        <div class="layui-input-block">
                            <input type="text" name="bankmch_id" value="{$cfg['bankmch_id']}" class="layui-input"/>
                            <div class="help-block">银行通道分配的商户号</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">支付密钥</label>
                        <div class="layui-input-block">
                            {if $cfg['bankpaykey']}
                            <input type="text" name="bankpaykey1" placeholder="修改密匙请直接输入" class="form-control"/>
                            <input type="hidden" name="bankpaykey" value="{$cfg['bankpaykey']}"/>
                            {else}
                            <input type="text" name="bankpaykey" value="{$cfg['bankpaykey']}" class="form-control"/>
                            {/if}
                            <div class="help-block">银行通道分配的支付密钥，基于安全问题，不显示</div>
                        </div>
                    </div>

                    <blockquote class="layui-elem-quote layui-quote-nm">微信支付参数</blockquote>
                    <div class="layui-form-item" >
                        <label class="layui-form-label">AppId</label>
                        <div class="layui-input-block">
                            <input type="text" name="appid" value="{$cfg['appid']}" class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">子商户AppId</label>
                        <div class="layui-input-block">
                            <input type="text" name="sub_appid" value="{$cfg['sub_appid']}" class="layui-input"/>
                            <div class="help-block">如果您是服务商，请在这里填写子商户的appid。如果不是服务商，请勿填写！</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">AppSecret</label>
                        <div class="layui-input-block">
                            <input type="text" name="appsecret" value="{$cfg['appsecret']}" class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商户名称</label>
                        <div class="layui-input-block ">
                            <input type="text" value="{$cfg['pay_name']}" class="layui-input" name="pay_name">
                            <div class="help-block">商户名称,不能多于6个中文字</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商户号</label>
                        <div class="layui-input-block">
                            <input type="text" value="{$cfg['pay_mchid']}" class="layui-input" name="pay_mchid">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">子商户商户号</label>
                        <div class="layui-input-block">
                            <input type="text" name="sub_mch_id" value="{$cfg['sub_mch_id']}" class="layui-input"/>
                            <div class="help-block">如果您是服务商，请在这里填写子商户的商户号。如果不是服务商，请勿填写！</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商户密钥</label>
                        <div class="layui-input-block">
                            <input type="text" value="{$cfg['pay_signkey']}" class="layui-input" name="pay_signkey">
                            <div class="help-block">如果出现错误提示【签名错误】，必然是此项出错。请检查是否有空格；如果依旧无法解决问题，请到【支付商户后台】修改支付密钥</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">IP</label>
                        <div class="layui-input-block">
                            <input type="text" value="{$cfg['pay_ip']}" class="layui-input" name="pay_ip">
                            <div class="help-block">服务器的IP</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">扫码回调地址</label>
                        <div class="layui-input-block">
                            <input type="text" value="{$cfg['notify_url']}" class="layui-input" name="notify_url">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商户证书</label>
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" id="rootca">
                                <i class="layui-icon">&#xe67c;</i>{if $cfg['rootca']}已上传{$cfg['rootca']}-点击修改{else}请上传rootca.pem{/if}
                            </button>
                            <input type="hidden" id="rootca2" name="rootca2" value="{$cfg['rootca']}"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商户证书</label>
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" id="apiclient_cert">
                                <i class="layui-icon">&#xe67c;</i>{if $cfg['apiclient_cert']}已上传{$cfg['apiclient_cert']}-点击修改{else}请上传apiclient_cert.pem{/if}
                            </button>
                            <input type="hidden" id="apiclient_cert2" name="apiclient_cert2" value="{$cfg['apiclient_cert']}"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商户证书</label>
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" id="apiclient_key">
                                <i class="layui-icon">&#xe67c;</i>{if $cfg['apiclient_key']}已上传{$cfg['apiclient_key']}-点击修改{else}请上传apiclient_key.pem{/if}
                            </button>
                            <input type="hidden" id="apiclient_key2" name="apiclient_key2" value="{$cfg['apiclient_key']}"/>
                        </div>
                    </div>
                    <blockquote class="layui-elem-quote layui-quote-nm">支付宝参数</blockquote>
                    <div class="layui-form-item">
                        <label class="layui-form-label">app_id</label>
                        <div class="layui-input-block">
                            <input type="text" name="app_id" value="{$cfg['app_id']}" class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">支付宝网关</label>
                        <div class="layui-input-block">
                            <input type="text" name="gatewayUrl" value="{php echo $cfg['gatewayUrl'] ? $cfg['gatewayUrl'] : 'https://openapi.alipay.com/gateway.do'}" class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">PID</label>
                        <div class="layui-input-block">
                            <input type="text" name="alipid" value="{$cfg['alipid']}" class="layui-input"/>
                            <div class="help-block">只有填写此PID才能有返佣。登陆https://open.alipay.com/，账号管理-角色身份中的pid</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">appAuthToken</label>
                        <div class="layui-input-block">
                            <input type="text" name="appauthtoken" value="{$cfg['appauthtoken']}" class="layui-input"/>
                            <div class="help-block">新版支付宝ISV中，应用签约用户的token。</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">支付宝公匙</label>
                        <div class="layui-input-block">
                            <textarea name="alipay_key" class="layui-input" id="alipay_key">{$cfg['alipay_key']}</textarea>
                            <div class="help-block">必须没有回车，中间没有空格。如果支付时提示【签名错误】，请检查此项目是否有回车或者空格</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">服务器私匙</label>
                        <div class="layui-input-block">
                            <textarea name="alipay_cert" class="layui-input" id="alipay_cert">{$cfg['alipay_cert']}</textarea>
                            <div class="help-block">必须没有回车，中间没有空格。如果支付时提示【签名错误】，请检查此项目是否有回车或者空格</div>
                        </div>
                    </div>

                </div>
            </div>
            <div class="panelbox">
                <div class="panelbox-head">卡券/会员参数</div>
                <div class="panelbox-body">
                    <div class="layui-form-item">
                        <label class="layui-form-label">微信卡券</label>
                        <div class="layui-input-block">
                            <div id="wxcard">
                                {php $wxcard=json_decode($cfg['wxcard'],true)}
                                {php $i=0}
                                {if count($wxcard)}
                                {loop $wxcard $index $row}
                                <div>
                                    <label wxold='{php echo $i}' class='form-inline' >
                                        <input class='form-control' name='wxcard-key[{php echo $i}]' required value='{$index}' placeholder='字段名'/>
                                        :
                                        <input class='form-control' name='wxcard-val[{php echo $i}]' required value='{$row}' placeholder='卡券ID'/>
                                        <a href="javascript:delwxcard({php echo $i})" class="layui-btn layui-btn-danger layui-btn-mini"><i class='fa fa-remove-circle'></i></a></label>
                                </div>
                                {php $i++}
                                {/loop}
                                {/if}
                            </div>
                            <a href="javascript:addwxcard()" class="layui-btn layui-btn-info layui-btn-small"><i class="fa fa-plus"></i> 添加</a>
                            <div class="help-block">请先到【粉丝营销】-【微信卡券】中生成微信卡券，然后填写卡券中的【卡券id】。<a href="./index.php?c=wechat&a=account" target="_blank">添加卡券</a></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">微信会员卡</label>
                        <div class="layui-input-block">
                            <input type="text" name="wxmembercard" value="{$cfg['wxmembercard']}" autocomplete="off" class="layui-input"/>
                            <div class="help-block">填写微信会员卡ID号</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">领取会员卡</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="isgetmembercard" lay-skin="switch" value="1" {if $cfg['isgetmembercard']}checked{/if} lay-text="自动领取|关闭"/>
                            <input type="text" name="getmembercardinfo" value="{$cfg['getmembercardinfo']}" autocomplete="off" class="layui-input"/>
                            <div class="help-block">如果是已经领取会员卡的用户，将跳转到会员卡；如果关闭则会提示内容</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">微信会员卡审核</label>
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn layui-btn-normal" onclick="postSetMemberactive(1)">需要审核</button>
                            <button type="button" class="layui-btn" onclick="postSetMemberactive(0)">不需要审核</button>
                            <div class="help-block">新领取微信会员卡的人需要填写资料（填写的资料请在微信后台设置）后，提交到后台审核。审核通过后，才有会员卡号。审核功能请在会员中</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">设置支付即会员</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="rule_id" value="{$cfg['rule_id']}" />
                                <button type="button" class="layui-btn" onclick="postSetMember()">设置支付即会员</button>
                                {if $cfg['rule_id']}
                                <button type="button" class="layui-btn layui-btn-danger" onclick="postSetMember2()">取消支付即会员</button>
                                {/if}
                                <div class="help-block">注意，必须先填写【微信会员卡】保存后再操作。如何设置不成功，请到微信商户后台设置</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">会员卡设置</label>
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" onclick="SetMembername()">显示余额</button>
                                <div class="help-block">注意，必须先填写【微信会员卡】保存后再操作</div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">开启通用余额</label>
                            <div class="layui-input-block">
                                <input type="checkbox" name="isgeneralbalance" lay-skin="switch" value="1" {if $cfg['isgeneralbalance']}checked{/if} lay-text="打开|关闭"/>
                                <div class="help-block">不开启，会员余额只能用于本系统中；如开启则使用通用余额。</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">消费积分</label>
                            <div class="layui-input-block form-inline">
                                <div class="input-group">
                                    <span class="input-group-addon">消费1分钱</span>
                                    <span class="input-group-addon">获得</span>
                                    <input type="text" class='form-control' name='credit' value='{php echo $cfg["credit"] ? $cfg["credit"] : 0}'/>
                                    <span class="input-group-addon">积分</span>
                                </div>
                                <div class="help-block">积分支持0.01。积分获得逻辑：如果是会员，那么积分将自动计算；如果非会员，则通过扫描小票上的二维码进行获得。</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">积分加密</label>
                            <div class="layui-input-block">
                                <input type="text" name="encryptcode" value="{$cfg['encryptcode']}" maxlength="8" autocomplete="off" class="layui-input"/>
                                <div class="help-block">请填写不多于8位数字/英文/符号，必须填写</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">支付验证码</label>
                            <div class="layui-input-block">
                                <input type="checkbox" name="ispaycode" lay-skin="switch" value="1" {if $cfg['ispaycode']}checked{/if} lay-text="打开|关闭"/>
                                <div class="help-block">开启支付验证时，会员卡支付时，将会发送4位验证码给会员（仅支持微信会员卡）。</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">验证码模板消息</label>
                            <div class="layui-input-block">
                                <input type="text" name="tempmsg_paycode" value="{$cfg['tempmsg_paycode']}"  autocomplete="off" class="layui-input"/>
                                <div class="help-block">会员卡支付码，使用模板消息【验证码下发通知】</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">小票回复</label>
                            <div class="layui-input-block">
                                <textarea name="returnstr"  style="height:150px; line-height:18px;" class="layui-input">{$cfg['returnstr']}</textarea>
                                <div class="help-block">当扫码小票时，回复的内容。标签|获得积分|,|总积分|,|昵称|,|奖励|</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="panelbox">
                <div class="panelbox-head">模板消息</div>
                <div class="panelbox-body">
                    <div class="layui-form-item">
                        <label class="layui-form-label">付款成功通知</label>
                        <div class="layui-input-block">
                            <input type="text" name="tempmsg_pay" value="{$cfg['tempmsg_pay']}" autocomplete="off" class="layui-input"/>
                            <div class="help-block">建议OPENTM200444326【订单付款成功通知】，用于针对公众号老粉丝交互超48小时时，通知客户</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">模板详情</label>
                        <div class="layui-input-block">
                            <textarea name="tempmsg_paycon" id="tempmsg_paycon" class="layui-input" style="margin-bottom:10px; height:150px; line-height:18px" rows="6">{$cfg['tempmsg_paycon']}</textarea>
                            <button type="button" class="btn btn-primary" onclick="resolve(1)">解析模板内容</button>
                            <div class="help-block"></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">模板参数</label>
                        <div class="layui-input-block">
                            <div id="tempmsg_payparama">

                            </div>
                            <div class="help-block">可用标签|单号|,|时间|,|总金额|,|优惠金额|,|实付金额|,|支付方式|,|店铺|,|优惠|</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">退款通知</label>
                        <div class="layui-input-block">
                            <input type="text" name="tempmsg_refunder" value="{$cfg['tempmsg_refunder']}" autocomplete="off" class="layui-input"/>
                            <div class="help-block">编号:【TM00431】，名称【退款申请通知】，行业【IT科技-互联网|电子商务】 </div>
                        </div>
                    </div>
                </div>
            </div>
            <div style=" padding:15px 0;"><button class="layui-btn col-md-1" lay-submit="" lay-filter="btnsubmit">保存</button></div>
        </div>
    </div>
</form>
{/if}

<script language="javascript">
    resolve();
    function resolve(){
        msg=$("#tempmsg_paycon").val() ? $("#tempmsg_paycon").val():$("#tempmsg_paycon").html();
        if(msg=='undefined' || msg=="" || msg.length<10)return;
        var test = /\{\{.*?\.(DATA)\}\}/gi;
        var result = [];
        var img ;
        $("#tempmsg_payparama").empty();
        var tempstr='{php echo $cfg["tempmsg_payparama"]}';
        var odata;

        while(img = test.exec(msg)){
            key=img[0].replace(" ","").replace("{{","").replace(".DATA}}","");
            var temp="<div><label class='form-inline'><input class='layui-input' readonly name='parama-key["+key+"] ' value='"+key+"'/> : <input class='layui-input' name='parama-val["+key+"]'/>  : <input class='layui-input' class='tcolor' name='parama-color["+key+"]'/> </label></div>";
            $("#tempmsg_payparama").append(temp);
            setcolor($('input[name="parama-color['+key+']"]'));
        }
        if(tempstr.length>10){
            odata=eval("("+tempstr+")");
            for(var i in odata){
                $("input[name='parama-val["+i+"]'").val(odata[i].value);
                //$("input[name='parama-val["+i+"]'").color(odata[i].color);
            }
        }
    }
    function setcolor(elm){
        require(['jquery', 'util'], function($, util){
            $(function(){
                util.colorpicker(elm, function(color){
                    elm.val(color);
                });
            });
        });
    }
    layui.use(['layer', 'element','form','upload'], function(){
        var layer = layui.layer
                ,element = layui.element
                ,form = layui.form;
        form.render();
        var upload = layui.upload;
        var uploadInst1 = upload.render({
            elem: "#rootca"
            ,url: "{php echo $this->createWebUrl('settings',array('op'=>'uploadpem'))}"
            ,accept:"file"
            ,field:"rootca"
            ,done: function(res){
                if(res.success){
                    layer.msg("上传成功",{icon:1,time:2000});
                    $("#rootca").text("已上传-点击修改");
                    $("#rootca2").val(res.filename);
                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }
            }
            ,error: function($indexx,$upload){
                layer.msg("上传失败，请检查文件夹是否有权限",{icon:1,time:2000});
            }
        });
        var uploadInst2 = upload.render({
            elem: "#apiclient_cert"
            ,url: "{php echo $this->createWebUrl('settings',array('op'=>'uploadpem'))}"
            ,accept:"file"
            ,field:"apiclient_cert"
            ,done: function(res){
                if(res.success){
                    layer.msg("上传成功",{icon:1,time:2000});
                    $("#apiclient_cert").text("已上传-点击修改");
                    $("#apiclient_cert2").val(res.filename);
                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }
            }
            ,error: function($indexx,$upload){
                layer.msg("上传失败，请检查文件夹是否有权限",{icon:1,time:2000});
            }
        });
        var uploadInst3 = upload.render({
            elem: "#apiclient_key"
            ,url: "{php echo $this->createWebUrl('settings',array('op'=>'uploadpem'))}"
            ,accept:"file"
            ,field:"apiclient_key"
            ,done: function(res){
                if(res.success){
                    layer.msg("上传成功",{icon:1,time:2000});
                    $("#apiclient_key").text("已上传-点击修改");
                    $("#apiclient_key2").val(res.filename);
                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }
            }
            ,error: function($indexx,$upload){
                layer.msg("上传失败，请检查文件夹是否有权限",{icon:1,time:2000});
            }
        });
        form.on('submit(btnsubmit)', function(data){
            var index2=layer.load(1, {shade: [0.5,'#fff']});
            $.post("{php echo $this->createWebUrl('settings',array('op'=>'post'))}",data.field,function(data){
                layer.close(index2);
                console.log(data);
                var result=eval("("+data+")");
                if(result.success){
                    location.reload();
                }
                layer.msg(result.msg,{icon:1,time:2000});
                return;

            });
            return false;
        });

    });
    function showTab(obj){
        var index=$(obj).index();
        $(obj).addClass("isselect").siblings().removeClass("isselect");
        $(".col-md-10 .panelbox").hide().eq(index).show();
    }
    function addwxcard(){
        var index=$("#wxcard div").size();
        var temp="<div><label wxold='"+index+"' class='form-inline'><input class='form-control' name='wxcard-key["+index+"]' required placeholder='字段名'/>:<input class='form-control' name='wxcard-val["+index+"]' required placeholder='卡券ID'/> <a href='javascript:delwxcard("+index+")' class='layui-btn layui-btn-danger layui-btn-mini'><i class='fa fa-remove-circle'></i></a></label></div>";
        $("#wxcard").append(temp);
    }
    function delwxcard(num){
        $("label[wxold='"+num+"']").parent().remove();
    }
    function postSetMember(){
        var index2=layer.load(1, {shade: [0.5,'#fff']});
        $.post("{php echo $this->createWebUrl('settings',array('op'=>'postsetmember'))}",{},function(data){
            layer.close(index2);
            console.log(data);
            var result=eval("("+data+")");
            if(!result.success){
                layer.msg(result.msg,{icon:2,time:2000});
                return;
            }
            $("input[name='rule_id']").val(result.rule_id);
            layer.msg("设置成功",{icon:1,time:2000});
            return;
        });
    }
    function postSetMemberactive(obj){
        url="{php echo $this->createWebUrl('settings',array('op'=>'setmemberactive1'))}";
        if(obj==0)url="{php echo $this->createWebUrl('settings',array('op'=>'setmemberactive2'))}";
        var index2=layer.load(1, {shade: [0.5,'#fff']});
        $.post(url,{},function(data){
            layer.close(index2);
            console.log(data);
            var result=eval("("+data+")");
            if(result.success){
                layer.msg("设置成功",{icon:1,time:2000});
                return;
            }
            layer.msg(result.msg,{icon:2,time:2000});
            return;
        });
    }
    function postSetMember2(){
        var index2=layer.load(1, {shade: [0.5,'#fff']});
        $.post("{php echo $this->createWebUrl('settings',array('op'=>'postsetmember2'))}",{},function(data){
            layer.close(index2);
            console.log(data);
            var result=eval("("+data+")");
            if(!result.success){
                layer.msg(result.msg,{icon:2,time:2000});
                return;
            }
            $("input[name='rule_id']").val('');
            layer.msg("修改成功",{icon:1,time:2000});
            return;
        });
    }
    function SetMembername(){
        var index2=layer.load(1, {shade: [0.5,'#fff']});
        $.post("{php echo $this->createWebUrl('settings',array('op'=>'SetMembername'))}",{},function(data){
            layer.close(index2);
            console.log(data);
            var result=eval("("+data+")");
            if(result.success){
                layer.msg("操作成功",{icon:1,time:2000});
            }else{
                layer.msg(result.msg,{icon:2,time:2000});
                return;
            }
        });
    }
</script>